import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import { ChangeUserInfoParams, UserInfoRes } from './type'

enum User_API {
  GET_POST_PUT_DELETE_USER_INFO = '/transaction_assistant/user/info',
  PUT_USER_COLORTHEME = '/transaction_assistant/user/colorTheme/{color}',
}

/**
 * 获取用户信息
 * @returns
 */
export const reqGetUserInfo = () =>
  request.get<any, AxiosResponse<UserInfoRes>>(
    User_API.GET_POST_PUT_DELETE_USER_INFO,
  )

/**
 * 添加用户信息
 * @param {object} params 用户信息添加表
 * @param {string} params.nickname 昵称
 * @param {string} params.introduction 个人介绍
 * @param {string} params.avatar 头像
 * @param {string} params.colorTheme 颜色主题
 * @returns
 */
export const reqAddUserInfo = (params: ChangeUserInfoParams) =>
  request.post<any, AxiosResponse<any>>(
    User_API.GET_POST_PUT_DELETE_USER_INFO,
    params,
  )

/**
 * 修改用户信息
 * @param {object} params 用户信息修改表
 * @param {string} params.nickname 昵称
 * @param {string} params.introduction 个人介绍
 * @param {string} params.avatar 头像
 * @returns
 */
export const reqChangeUserInfo = (params: ChangeUserInfoParams) =>
  request.put<any, AxiosResponse<any>>(
    User_API.GET_POST_PUT_DELETE_USER_INFO,
    params,
  )

/**
 * 修改用户颜色主题
 * @param {string} color
 * @returns
 */
export const reqChangeUserColorTheme = (color: string) =>
  request.put<any, AxiosResponse<any>>(
    User_API.PUT_USER_COLORTHEME.replace('{color}', color),
  )

/**
 * 注销用户
 * @returns
 */
export const reqDeleteUser = () =>
  request.delete<any, AxiosResponse<any>>(
    User_API.GET_POST_PUT_DELETE_USER_INFO,
  )
